/*
 * Created on 2005/4/13
 *
 */
package com.erp.app.util.popupSearchTemplate;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Hashtable;
import java.util.LinkedList;

import com.erp.app.common.ProjectConstants;
import com.erp.app.util.web.WebUtil;
import com.erp.common.web.SearchResultRow;
import com.erp.framework.util.CommonUtil;

public class ItemPopupSearchTemplate extends PopupSearchTemplateFactory {
    protected static final ItemPopupSearchTemplate template = new ItemPopupSearchTemplate();

    private ItemPopupSearchTemplate() {
        super("itemCode");
    }

    protected static void init() {
    }

    public void execute(PopupSearchTemplateComponent comp) {
        LinkedList criteriaList = new LinkedList();
        ArrayList criteriaColumnList = new ArrayList();
        ArrayList rsltTextList = new ArrayList();
        ArrayList rsltColumnList = new ArrayList();
        Hashtable tblParams = new Hashtable();
        HashMap params = new HashMap();
        StringBuffer sb = null;

        
        criteriaList.add("Item Code.");
        criteriaList.add("INPUT");
        criteriaList.add("");

        criteriaColumnList.add("UPPER(ITEM_CODE)");

        rsltTextList.add("Item Code");
        rsltTextList.add("Short Description");
        
        rsltColumnList.add("ITEM_CODE");
        rsltColumnList.add("SHORT_DESC");
        
        String table = " T_ITEM_HDR";
        String whereClause = "";
        tblParams.put(ProjectConstants.SESSION_TABLE, table);
        tblParams.put(ProjectConstants.SESSION_WHERE, whereClause);
        tblParams.put(ProjectConstants.SESSION_ORDERBY, "ITEM_CODE ASC");

        if (comp.isExclusive())
            params.put(ProjectConstants.SESSION_EXCLUSIVE, ProjectConstants.GENERIC_YES);
        if (!CommonUtil.isEmpty(comp.getEventSrc()))
            params.put(ProjectConstants.SESSION_EVENTSRC, comp.getEventSrc());
        params.put(ProjectConstants.SESSION_SESSION_NAME, comp.getSessionKeyStatus());
        params.put(ProjectConstants.SESSION_SESSION_VALUE, comp.getSessionValueStatus());
        params.put(ProjectConstants.SESSION_OPENER_PATH, comp.getFunctionId());
        params.put(ProjectConstants.SESSION_CRITERIA_LIST, criteriaList);
        params.put(ProjectConstants.SESSION_CRITERIA_COLUMN_LIST, criteriaColumnList);
        params.put(ProjectConstants.SESSION_RESULT_TEXT_LIST, rsltTextList);
        params.put(ProjectConstants.SESSION_RESULT_COLUMN_LIST, rsltColumnList);
        params.put(ProjectConstants.SESSION_TABLE_PARAMS, tblParams);

        comp.getSession().setAttribute(ProjectConstants.SESSION_COMMON_SEARCH_PARAMETERS, params);
    }

    public Object getSearchResultValue(SearchResultRow row) {
        return row.getColumn1();
    }

    public Object getSearchResultLabel(SearchResultRow row) {
        return row.getColumn2();
    }

}
